package com.ruoyi.system.pay.mapper;

import com.ruoyi.system.pay.domain.po.PayRefund;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 退款记录表 Mapper
 */
@Mapper
public interface PayRefundMapper {

    /**
     * 通过订单 ID 查询退款记录
     */
    @Select("SELECT * FROM pay_refund WHERE order_id = #{orderId}")
    List<PayRefund> findByOrderId(@Param("orderId") Long orderId);

    /**
     * 通过退款状态查询
     */
    @Select("SELECT * FROM pay_refund WHERE status = #{status}")
    List<PayRefund> findByStatus(@Param("status") String status);

    /**
     * 新增退款记录
     */
    @Insert("INSERT INTO pay_refund (order_id, transaction_id, refund_amount, status, reason, apply_time) " +
            "VALUES (#{orderId}, #{transactionId}, #{refundAmount}, #{status}, #{reason}, NOW())")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertRefund(PayRefund refund);

    /**
     * 更新退款状态
     */
    @Update("UPDATE pay_refund SET status = #{status}, completed_time = NOW() WHERE id = #{id}")
    int updateRefundStatus(@Param("id") Long id, @Param("status") String status);
}
